package com.enation.app.web.tag;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.enation.framework.component.ComponentView;
import com.enation.framework.component.IComponentManager;
import com.enation.framework.taglib.BaseFreeMarkerTag;

import freemarker.template.TemplateModelException;

/**
 * 
 * @function 检查是否安装组件
 * @author 闯哥
 * @time 2016年11月13日 下午7:00:13
 */
@Component
public class IsComponentTag extends BaseFreeMarkerTag {
	
	@Autowired
	private IComponentManager componentManager;

	@Override
	protected Object exec(Map params) throws TemplateModelException {
		int flag=0;
		String componentName=params.get("componentName").toString();
		List<ComponentView> componentList = this.componentManager.list();
		for (ComponentView componentView : componentList) {
			if (componentName.equals(componentView.getName())) {
				if (componentView.getInstall_state()==1) {
					if (componentView.getEnable_state()==1) {
						flag=1;
					}
				}
			}
		}
		return flag;
	}

}
